package ModelLayer;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.*;
import java.util.ArrayList;

/**
 * The test class tester.
 *
 * @author  (your name)
 * @version (a version number or a date)
 */
public class TestCustomer
{
    private Random randomGenerator = new Random();
    /**
     * Default constructor for test class tester
     */
    public TestCustomer()
    {
    }

    /**
     * Sets up the test fixture.
     *
     * Called before every test case method.
     */
    @Before
    public void setUp()
    {
    }

    /**
     * Tears down the test fixture.
     *
     * Called after every test case method.
     */
    @After
    public void tearDown()
    {
    }

    /**
     * Test that adds 22 groups of customers and 1,000 customers devided in these groups.
     * After that that every customer from the database by ID and deletes him. 
     */
    @Test
    public void test_adding_thousand()
    {
        ModelLayer.CustomerCollection.initialize();
        add_groups();
        delete_customers(add_customers());
        ModelLayer.CustomerCollection.save_all_data();
    }
     /**
     * Test that adds 22 groups of customers(As many as the company desired). 
     */
    private void add_groups()
    {
        for (int i = 0; i < 22; i++)
        {
            assertEquals(true, ModelLayer.CustomerCollection.add_group(i + "","No delivery", randomGenerator.nextDouble()));
        }
    }
    
     /**
     * Test that adds 1000 customers. 
     */
    private ArrayList<String> add_customers()
    {
        ArrayList<String> customers = new ArrayList<>();
        for (int i = 0; i < 1000; i++)
        {
            customers.add(ModelLayer.CustomerCollection.add_customer("Joshua Black", "54675678", "Boulevarden 31, 2.TH", "" + (randomGenerator.nextInt(9000) + 1000), "Aalborg", "" + randomGenerator.nextInt(22)));
        }
        return customers;
    }
    
     /**
     * Test that deletes 1000 customers. 
     */
    private void delete_customers(ArrayList<String> customers)
    {
        for (int i = 0; i < 1000; i++)
        {
            assertEquals(true, ModelLayer.CustomerCollection.existing_customer(customers.get(i)));
            assertEquals(true, ModelLayer.CustomerCollection.delete_customer(customers.get(i)));
        }
    } 
}
